        <!-- BOX DIREITO -->
        <td colspan="2" valign="top" style="border-left:1px solid #bbb; border-right:1px solid #ccc; padding:20px 12px;">
            <div id="titulo_pagina">Despesas</div>
            <p>Manuten&ccedil;&atilde;o das Despesas.</p>
   			<script type="text/javascript">
   				<?php
   				//Variaveis para configuracao da GRID
   				//$gridName - ID da GRID
   				//$controller - Controlador da GRID
   				//$titleList - Titulo da GRID
   				//$titleForm - Titulo do Formulario
   				$gridName = "gridDespesas";
   				$controller = "despesas";
   				$titleList = "Lista de Despesas";
   				$titleForm = "Formul&aacute;rio de Despesas";
   				?>
   				//Array com todos os campos da tabela.
				var arr_fields = [
				                  {nome:'id_despesa',label:'Id', tp_obj: 'hid', tipo : 'str', grid:{name:'id_despesa',index:'id_despesa', width:15, def_order:true,order:'asc'}},
				                  {nome:'id_operacao_fk',label:'Opera&ccedil;&atilde;o', tp_obj: 'sel', tipo : 'str', grid:{name:'id_operacao_fk',index:'id_operacao_fk', width:15, def_order:false,order:''}},
				                  {nome:'descricao',label:'Descri&ccedil;&atilde;o', tp_obj: 'txt', tipo : 'str', grid:{name:'descricao',index:'descricao', width:170, def_order:false,order:''}},
				                  {nome:'flag_ativo',label:'Despesa Ativo?', tp_obj: 'sel', tipo : 'str', grid:{name:'flag_ativo',index:'flag_ativo', width:60, def_order:false,order:'', formatter:format_flag}},
				                  {nome:'hid_oper',label:'', tp_obj: 'hid', tipo : 'str', grid:null}
					              	];

				//Variavel com o codigo da linha selecionada
				var editValue = null;
				$(document).ready(function(){
					var arr_fld_grid = new Array();
					var arr_fld_labels = new Array();
					var fld_sort_name = "";
					var fld_sort_order = "";

					//Monta os arrays com os labels e os campos
					for(i=0; i<arr_fields.length; i++)
					{
						if(arr_fields[i].grid != null)
						{
							arr_fld_grid.push(arr_fields[i].grid);
							arr_fld_labels.push(arr_fields[i].label);
							if(arr_fields[i].grid.def_order)
							{
								fld_sort_name = arr_fields[i].grid.name;
								fld_sort_order = arr_fields[i].grid.order;
							}
						}
					}

					//Montagem da GRID
					jQuery("#<?php echo $gridName; ?>").jqGrid({
					   	url:'<?php echo base_url().$controller."/listAll"?>',
						datatype: "json",
					   	colNames:arr_fld_labels,
					   	colModel:arr_fld_grid,
					   	rowNum:10,
					   	rowList:[5,10,20,30],
					   	height: 'auto',
					   	width:'850',
					   	pager: '#p<?php echo $gridName; ?>',
					   	sortname: fld_sort_name,
					    viewrecords: true,
					    sortorder: fld_sort_order,
					    caption:'<?php echo $titleList; ?>',
					    onSelectRow: function(id){ 
							if(id && id!==editValue){ 
								editValue=id; 
							} 
						},
						grouping:true,
					   	groupingView : {
					   		groupField : ['id_operacao_fk'],
					   		groupColumnShow : [false],
					   		groupText : ['<b>Opera&ccedil;&atilde;o: {0}</b>']
					   	}
					})
					.navGrid('#p<?php echo $gridName; ?>',{edit:false,add:false,del:false,search:false,refresh:false},{},{},{})
				});

				//Validacao e envio do formulario
				$(function() {

					var id_operacao_fk = $("#id_operacao_fk"),
						descricao = $("#descricao"),
						flag_ativo = $("#flag_ativo"),
					allFields = $([])
									.add(id_operacao_fk)
									.add(descricao)
									.add(flag_ativo),
					tips = $(".validateTips");
	    			
				    $("#dialog-form").dialog({
					    bgiframe: true,
					    autoOpen: false,
					    height: 340,
					    width: 350,
					    modal: true,
					    buttons: {
						    'Cancelar': function() {
							    $(this).dialog('close');
					    		fc_reset_form(arr_fields);
						    }, 
						    'Salvar': function()
						    {
								var bValid = true;
								allFields.removeClass('ui-state-error');

								bValid = bValid && validation(id_operacao_fk, "Opera\u00e7\u00e3o", "required", tips, 0, 0);
								bValid = bValid && validation(descricao, "Descri\u00e7\u00e3o", "required", tips, 0, 0);
								bValid = bValid && validation(descricao, "Descri\u00e7\u00e3o", "length", tips, 1, 150);

								if(bValid)
								{
						            $('#dialog-wait').dialog({ 
						            	closeOnEscape: false,
						            	draggable: false,
						            	modal: true,
						            	resizable: false  
						            });
									eval(fc_get_fields(arr_fields));
									$.ajax({
										  type: 'POST',
										  url: '<?php echo base_url().$controller."/save"?>',
										  data: arr_data,
										  success: function(msg){
										  		var type = msg.substr(0,3);
												var msgs = msg.substr(4);
										  		if(type != "err")
										  		{
													showMsg(msgs);
													$("#<?php echo $gridName; ?>").trigger("reloadGrid");
													editValue = null;
										    		fc_reset_form(arr_fields);
													allFields.val('').removeClass('ui-state-error');
										  			document.getElementById('error').innerHTML= "";
										  			document.getElementById("error").style.display='none';
										  			tips.removeClass('ui-state-highlight', 1500);
													$("#dialog-form").dialog('close');
										  		}
										  		else
										  		{
										  			document.getElementById('error').innerHTML= msgs;
										  			document.getElementById("error").style.display="";
											  	}
											}
									});
									$('#dialog-wait').dialog('close');
								}
							}
					    },
					    open: function() {
			                $('.ui-dialog-buttonpane').
			                    find('button:contains("Cancelar")').button({
			                    icons: {
			                        primary: 'cancelIcon'
			                    }
			                });
			                $('.ui-dialog-buttonpane').
		                    find('button:contains("Salvar")').button({
		                    icons: {
		                        primary: 'saveIcon'
		                    }
		                });
			             },
					    close: function() {				
					    }
				    });
				});		
			</script>
			<script>
				$(document).ready(function() {
		            $("#bt_add").button({
			            icons: {primary: "addIcon"}
		            }).click(function(){
						$('#dialog-form').dialog('option', 'title');
			            $('#dialog-form').dialog('open');
						$('#hid_oper').val("add");
		    		});

		            $("#bt_edit").button({
			            icons: {primary: "editIcon"}
		            }).click(function(){
					   if(editValue != null)
					   {
							$('#dialog-form').dialog('open');
				            $('#dialog-wait').dialog({ 
					            	closeOnEscape: false,
					            	draggable: false,
					            	modal: true,
					            	resizable: false  
					            });
							$.ajax({
		                        type: "POST",
		                        url: '<?php echo base_url().$controller."/getById"?>',
		                        data: {id:editValue},
		                        success: function(msg) 
		                        {
									var obj = msg;
									fc_edit(arr_fields, obj);	
									$('#hid_oper').val("upd");
		                        }
							});
							$('#dialog-wait').dialog('close');
					   }
					   else
					   {
						   dialogMessage('Selecione uma linha','dialog-message');   
							$("#<?php echo $gridName; ?>").trigger("reloadGrid");
					   }
					});

		            $("#bt_delete").button({
			            icons: {primary: "deleteIcon"}
		            }).click(function(){
		            	if(editValue != null)
					   	{
				   			$("#dialog-confirm").dialog({
				   				resizable: false,
				   				height:150,
				   				width:400,
				   				modal: true,
				   				buttons: {
				   					'Confirmar': function() {
        					            $('#dialog-wait').dialog({ 
        					            	closeOnEscape: false,
        					            	draggable: false,
        					            	modal: true,
        					            	resizable: false  
        					            });
										$.ajax({
				                    		type: "POST",
				                    		url: '<?php echo base_url().$controller."/delete"?>',
				                    		data: {id:editValue},
				                    		success: function(msg) 
				                    		{
										  		var type = msg.substr(0,3);
												var msgs = msg.substr(4);

												if(type != "err")
												{
						   							showMsg(msgs);
												}
												else
												{
													dialogMessage(msgs,'dialog-message');   
												}
						       					$("#<?php echo $gridName; ?>").trigger("reloadGrid");
						       					editValue = null;
				                    		}
										});
										$('#dialog-wait').dialog('close');
				   						$(this).dialog('close');
				   					},
				   					Cancelar: function() {
				   						$(this).dialog('close');
				   					}
				   				}
				   			}); 
					   	}
				   		else
				   		{
							   dialogMessage('Selecione uma linha','dialog-message');   
								$("#<?php echo $gridName; ?>").trigger("reloadGrid");
					   	}
					});

		            $("#bt_search").button({
			            icons: {primary: "searchIcon"}
		            }).click(function(){
						jQuery("#<?php echo $gridName; ?>").jqGrid('searchGrid',{multipleSearch:true});
		    		});

		            $("#bt_refresh").button({
			            icons: {primary: "refreshIcon"}
		            }).click(function(){
		            	$("#<?php echo $gridName; ?>").trigger("reloadGrid");
		    		});
		            
				});	    			
    		</script> 
			<style>
            	#toolbar {
            		padding: 2px 4px;
					width:840px;
            	}
        	</style>
			<div align="center">
                <div id="toolbar" class="ui-widget-header ui-corner-all">
                	<table border="0" cellpadding="0" cellspacing="0" width="100%">
                		<tr>
                			<td align="left" width="33%">
            				<?php 
            					$actions = $this->session->userdata('v_actions');
            					
            					if(in_array("ADD", $actions[$controller]))
            					{
            					?>
            	                <button id="bt_add">Novo</button>
            	                <?php 
            					}
            					
            					if(in_array("UPD", $actions[$controller]))
            					{
            	                ?>
                            	<button id="bt_edit">Editar</button>
            	                <?php 
            					}
            					
            					if(in_array("DEL", $actions[$controller]))
            					{
            	                ?>
                            	<button id="bt_delete">Deletar</button>
                            	<?php 
            					}
                            	?>
                			</td>
                			<td align="center" width="34%">
            	                <?php 
            					if(in_array("PES", $actions[$controller]))
            					{
            	                ?>
                            	<button id="bt_search">Pesquisar</button>
            	                <?php 
            					}
            					
            					if(in_array("REF", $actions[$controller]))
            					{
            	                ?>
                            	<button id="bt_refresh">Recarregar</button>
                            	<?php 
            					}
                            	?>
                			</td>
                			<td align="right" width="33%">
                				&nbsp;
                			</td>
                		</tr>
                	</table>
                </div>
				<table id="<?php echo $gridName; ?>"></table>
				<div id="p<?php echo $gridName; ?>"></div>
			</div>
			<div id="dialog-form" title="<?php echo $titleForm; ?>">
				<div id="error" class="ui-state-highlight" style="display:none;"></div>
				<p class="validateTips">Todos os campos s&atilde;o obrigat&oacute;rios.</p>
				<fieldset>
					<form>
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
							<tr>
								<td>
									<label for="id_operacao_fk">Opera&ccedil;&atilde;o</label>
									<br />
									<select name="id_operacao_fk" id="id_operacao_fk" class="select ui-widget-content ui-corner-all">
									<?php 
									foreach ($operacoes as $dados) 
									{
									?>
										<option value="<?php echo $dados->id_operacao; ?>"><?php echo utf8_decode($dados->descricao); ?></option>
									<?php
									}
									?>
									</select>
								</td>
							</tr>
							<tr height="10px">
								<td>&nbsp;</td>
							</tr>
							<tr>
								<td>
									<label for="descricao">Descri&ccedil;&atilde;o</label>
									<br />
									<input type="text" name="descricao" id="descricao" class="text ui-widget-content ui-corner-all" size="30" />
								</td>
							</tr>
							<tr height="10px">
								<td>&nbsp;</td>
							</tr>
							<tr>
								<td>
									<label for="flag_ativo">Despesa Ativa?</label><br />
									<select name="flag_ativo" id="flag_ativo" class="select ui-widget-content ui-corner-all">
										<option value="S">Sim</option>
										<option value="N">N&atilde;o</option>
									</select>
								</td>
							</tr>
							<tr height="10px">
								<td>&nbsp;</td>
							</tr>
						</table>
    					<input type="hidden" id="hid_oper" value="" />
						<input type="hidden" id="id_despesa" value="" />
    				</form>
				</fieldset>
			</div>
        </td>
        <!-- X BOX DIREITO -->